import React, { Component } from 'react'
import TitleBack from "../../components/TitleBack/TitleBack"
import { reqgetcountdown, reqgetgroupon, reqgetindexgoods, reqgetnew, reqgetseckill } from '../../http/api'
import Goods from './components/Goods/Goods'
import Groupen from './components/Groupen/Groupen'
import New from './components/New/New'
import Seckill from './components/Seckill/Seckill'

export default class Home extends Component {
    constructor() {
        super()
        this.state = {
            getnewList: [],
            getgrouponLIst: [],
            getcountdown: [],
            getseckill: [],
            indexgoods: []
        }
    }
    async componentDidMount() {
        // 新人专享
        let res1 = await reqgetnew();
        if (res1.data.code === 200) {
            this.setState({
                getnewList: res1.data.list
            })
        };
        // 万人团
        let rse2 = await reqgetgroupon();
        if (rse2.data.code === 200) {
            this.setState({
                getgroupon: rse2.data.list
            })
        }
        // 倒计时
        let res3 = await reqgetcountdown();
        if (res3.data.code === 200) {
            this.setState({
                getcountdown: res3.data.list
            })
        }
        // 秒杀
        let res4 = await reqgetseckill();
        if (res4.data.code === 200) {
            this.setState({
                getseckill: res4.data.list
            })
        }
        // 首页商品信息
        let res5 = await reqgetindexgoods();
        if (res5.data.code === 200) {
            this.setState({
                indexgoods:res5.data.list
            })
        }
    }
    render() {
        let { getnewList, getgroupon, getcountdown, getseckill,indexgoods } = this.state
        return (
            <div>
                <TitleBack title={"首页"}></TitleBack>
                {/* 新人专享 */}
                <New getnewList={getnewList} getcountdown={getcountdown}></New>
                {/* 万人团 */}
                <Groupen getgroupon={getgroupon}></Groupen>
                {/* 秒杀 */}
                <Seckill getseckill={getseckill}></Seckill>
                {/* 商品列表 */}
                {indexgoods.length>0?<Goods indexgoods={indexgoods}></Goods>:[]}
            </div>
        )
    }
}
